/*
 * Copyright (c) 2011  Cristian Constantin
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @author Cristian Constantin
 * @since 11/5/11
 */

Ext.define('Quizio.view.QuizPanel', {
    extend: 'Ext.panel.Panel',
    alias : 'widget.quizpanel',

    layout: 'fit',

    initComponent: function() {

        this.bbar = Ext.create('Ext.toolbar.Toolbar', {
            region: 'south',
            items: [
                {
                    text: 'Submit answer',
                    iconCls: 'player-submit',
                    action: 'submit',
                    scale: 'large'
                },
                '-',
                {
                    text: 'Next question',
                    iconCls: 'player-next',
                    action: 'next',
                    plugins: 'confirmaction',
                    iconAlign: 'right',
                    scale: 'large'
                },
                '->',
                {
                    text: 'Close',
                    action: 'submit-quiz',
                    plugins: 'confirmaction',
                    iconCls: 'player-quit',
                    scale: 'large'
                },
                {
                    text: 'Quit',
                    action: 'quit',
                    plugins: 'confirmaction',
                    iconCls: 'player-quit',
                    scale: 'large'
                }
            ]
        });

        this.callParent(arguments);
    },


    loadQuestion: function(questionInfo) {
        this.removeAll();

        var question = questionInfo.question;
        var options = [];

        Ext.each(question.options, function(item) {
            options.push({
                boxLabel  : item.prompt,
                name      : 'answer',
                inputValue: item.id
            })
        });

        this.add(
            {
                xtype: 'form',
                border: false,
                padding: 10,
                items:[
                    {
                        html: question.prompt,
                        region: 'center',
                        margin: 10,
                        bodyCls: 'question-prompt',
                        border: false
                    },
                    {
                        xtype      : 'radiogroup',
                        vertical: true,
                        value: {'answer': questionInfo.answer},
                        columns: 1,
                        defaults: {
                            margin: 15
                        },
                        items: options
                    }
                ]
            }
        )
    },

    getUserInput: function() {
        return this.query("form radiogroup")[0].getValue();
    }
});